package com.repair.controller;

import com.repair.service.RepairTrackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.Map;

@RestController
@RequestMapping("/api/admin/tracks")
public class AdminTrackController {

    @Autowired
    private RepairTrackService repairTrackService;

    /**
     * 获取维修工指定日期的轨迹数据
     */
    @GetMapping("/{repairmanId}")
    public ResponseEntity<?> getRepairmanTracks(
            @PathVariable Long repairmanId,
            @RequestParam String date) {
        try {
            LocalDate trackDate = LocalDate.parse(date);
            Map<String, Object> data = repairTrackService.getRepairmanTracksByDate(repairmanId, trackDate);
            return ResponseEntity.ok(data);
        } catch (Exception e) {
            return ResponseEntity.badRequest().body("获取轨迹数据失败：" + e.getMessage());
        }
    }

    /**
     * 获取订单相关的轨迹数据
     */
    @GetMapping("/order/{orderId}")
    public ResponseEntity<?> getOrderTracks(@PathVariable Long orderId) {
        try {
            return ResponseEntity.ok(repairTrackService.getOrderTracks(orderId));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body("获取订单轨迹失败：" + e.getMessage());
        }
    }

    /**
     * 根据状态获取订单轨迹
     */
    @GetMapping("/order/{orderId}/status/{status}")
    public ResponseEntity<?> getOrderTracksByStatus(
            @PathVariable Long orderId,
            @PathVariable Integer status) {
        try {
            return ResponseEntity.ok(repairTrackService.getOrderTracksByStatus(orderId, status));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body("获取订单状态轨迹失败：" + e.getMessage());
        }
    }
} 